﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightPlayground.RFB.Security
{
    public class RfbVNCChallengeSecurityToken : RfbSecurityToken
    {
        /// <summary>
        /// Gets or sets the password.
        /// </summary>
        /// <value>The password.</value>
        public string Password { get; set; }
        /// <summary>
        /// Gets or sets the challenge.
        /// </summary>
        /// <value>The challenge.</value>
        private byte [] Challenge { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="RfbVNCChallengeSecurityToken"/> class.
        /// </summary>
        /// <param name="challenge">The challenge.</param>
        public RfbVNCChallengeSecurityToken(byte [] challenge)
        {
            this.Password = string.Empty;
            this.Challenge = challenge;
        }

        /// <summary>
        /// Serializes this instance.
        /// </summary>
        /// <returns></returns>
        public override byte[] Serialize()
        {
            RfbEncryption.EncryptBytes(this.Challenge, this.Password);
            return this.Challenge;
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return this.Password;
        }
    }
}
